// component/card/currentPatient.js
const wxbarcode = require("../../utils/wxbarcode")
const cache = require("../../utils/cache")
Component({
  /**
   * 组件的属性列表
   */
  options: {
    styleIsolation: 'isolated'
  },
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    showModal: false,
    currentPatient: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleShowQrcode(e) {
      if (this.data.currentPatient != undefined && this.data.currentPatient != '' && this.data.currentPatient != null) {
        wx.navigateTo({
          url: '/pages/user/barcode?barcode=' + this.data.currentPatient.ioNo,
        })
      }
    },
    loadImage() {
      let userInfo = cache.getValue("scope.userInfo");
      if (userInfo != undefined && userInfo != null && userInfo != '') {
        this.setData({
          image: userInfo.avatarUrl
        })
      }
    }
  },
  lifetimes: {
    attached: function () {
      let cachePtList = cache.getValue("patient");
      if (cachePtList != undefined && cachePtList != null && cachePtList.length > 0) {
        cachePtList.forEach(m => {
          if (m.crtFlag == "Y") {
            this.data.currentPatient = m
            this.loadImage()
            this.setData({
              currentPatient: this.data.currentPatient
            })
          }
        })
      }
    }
  }
})